package vistas;

import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import beans.EntidadBean;

import controller.ControllerPrincipal;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class AltaCliente extends DetalleCliente {

	public AltaCliente() {
		super();

	}

	@Override
	protected void initGUI() {
		super.initGUI();
		
		getContentPane().remove(btnEliminar);
		btnModificar.setText("GRABAR");
		ActionListener[] actions = btnModificar.getActionListeners();
		labelTitulo.setText("Alta de Usuario");
		this.setSize(553, 338);
		//limpio el comportamiento
		for(ActionListener act: actions){
			btnModificar.removeActionListener(act);
		}
		btnModificar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if(!ControllerPrincipal.getInstancia().validarClienteExistenteByCuil(jTextCuil.getText())){
						EntidadBean eb = new EntidadBean(jTextCuil.getText(), JTextRS.getText(),jTextIVA.getText());
						ControllerPrincipal.getInstancia().AltaCliente(eb);
						JOptionPane.showMessageDialog(null, "El usuario fue cargado satisfactoriamente", "", JOptionPane.INFORMATION_MESSAGE);
						_exit();
					}
					else{
						JOptionPane.showMessageDialog(null, "El usuario ya existe en el sistema", "Error", JOptionPane.INFORMATION_MESSAGE);
					}
				} catch (HeadlessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}

	@Override
	protected void deshabilitarCampos() {
		//
	}

}
